package com.daowen.bll;

import com.daowen.dal.DALBase;
import com.daowen.entity.Comment;

import java.text.MessageFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class CommentBLL {

    public static String getComments(String type,String belongid){

        StringBuffer sb=new StringBuffer();
        sb.append("<h4>评论信息</h4>");
        sb.append("<ul>");
        List list=DALBase.getEntity("comment", MessageFormat.format(" where xtype=''{0}'' and belongid=''{1}''",type,belongid));

        for(Iterator<Comment> it=list.iterator();it.hasNext();)
        {
            Comment c=it.next();
            sb.append("<li>");
            sb.append("<div class='comment-item'>");
            sb.append("<div class=\"comment-user\">");
            sb.append("<div class='pic fn-left'>");
            sb.append(MessageFormat.format("<img width=\"48\" height=\"48\" src=\"{0}\" />",c.getPhoto()));

            sb.append("</div>");
            sb.append("<div style='width:80px;' class=\"fn-left\">");
            String times="";
            long time=new Date().getTime()- c.getCommenttime().getTime();
            time=time/1000;//转成秒
            long day = time/(60*60*24);//转换成天
            time=time%(60*60*24);//剩下多少秒
            long hour=time/(60*60);//转换成时间
            time=time%(60*60);//剩下多少秒
            long minuter=time/60;//剩下多少分钟

            if(minuter!=0){
                times=minuter+"分钟前";
            }
            if(hour!=0){
                times=hour+"小时前";
            }
            if(day!=0){
                times=day+"天前";
            }

            sb.append(MessageFormat.format("<div>{0}</div>", times));
            sb.append(MessageFormat.format("<div>{0}</div>", c.getCommentren()));
            sb.append("</div>");
            //comment-user
            sb.append("</div>");
            sb.append("<div class='item-content'>");
            sb.append(c.getCommentcontent());
            sb.append("</div>");

            //comment-item
            sb.append("</div>");
            sb.append("</li>");


        }
        sb.append("</ul>");

        return sb.toString();



    }


}
